/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once

#define ComponentH(className, humanReadableName)\
public:\
	IComponent* clone() const;\
	const char8_t* componentName() { return #humanReadableName; }\
	HObjectH(className)

#define ComponentCPP(className)\
	HObjectCPP(className)

#include "hhdIHObject.h"
#include "hhdIMessageReceiver.h"
#include "hhdParameterField.h"
#include "hhdVector.hpp"

namespace hhd
{
	class IMessage;
	class IRenderInfo;
	class GameObject;
	class TScene;
	class GameTimer;
	class String;

	class IComponent : public IHObject, public IMessageReceiver
	{
	public:
		IComponent();
		virtual ~IComponent() { _parent = NULL; }

		// sets up anything extra
		virtual void initialize();

		// called by game object in the loop
		virtual void update(const GameTimer& in_gt);

		// called when it is set to receive a message
		//virtual void message(const IMessage* in_message);
			
		// get the parent of this component
		GameObject* getParentGameObject();

		const GameObject* getParentGameObject() const;

		// set the parent of thsi component
		void setParentGameObject(GameObject* in);

		// get the scene this component is a member of
		virtual TScene* getParentScene() const;

		// make an exact copy of this component
		virtual IComponent* clone() const = 0;

		/** Parsing methods **/
		// get the name of this component
		virtual const char8_t* componentName() = 0;

		// read xml for this component and set it up as appropriate
		virtual IComponent* readXML(const String& in_xml);

		/** Preallocated methods **/
		virtual void reset() = 0;
		virtual IHObject* instance() const = 0;
		virtual const char8_t* hObjectName() const = 0;
		virtual uint32_t hObjectIdInstance() const = 0;

		void registerComponent( IComponent* in_component);

		inline bool isActive() const
		{
			return _component_active;
		}
			
	protected:
		/** Overrides IMessageReceiver's handleMessages method **/
		void handleMessages();

		void setActivity(bool in_activity);

		/**
		Virtual method which is called when the component is changed to active
		**/
		virtual void onSetActive()
		{
		}

		/**
		Virtual method which is called when the component is changed to inactive
		**/
		virtual void onSetInactive()
		{
		}

		friend class GameObject;
		friend class GUIPanel;

		GameObject* _parent;
		ParameterField _pf;
		bool _component_active;
		Vector<IComponent*> _registered_components;
	};
}
